package test;
import static org.junit.Assert.*;

import java.util.TreeSet;




public class Sort {

	@org.junit.Test
	public void testSort() {
		
		TreeSet<MyInt> set= new TreeSet<Sort.MyInt>();
		
		set.add(new MyInt(true, false));
		set.add(new MyInt(false, false));
		set.add(new MyInt(true, true));
		
		System.out.println(set);
	
		set.clear();
		set.add(new MyInt(false, false));
		set.add(new MyInt(true, false));
		set.add(new MyInt(true, true));
		set.add(new MyInt(false, true));
		set.add(new MyInt(true, false));
		set.add(new MyInt(true, true));
		
		System.out.println(set);
		
	}
	
	public static class MyInt implements Comparable<MyInt>{
		public boolean fromBar;
		public boolean hit;

		public MyInt(boolean fromBar, boolean hit) {
			super();
			this.fromBar = fromBar;
			this.hit = hit;
		}
		
		@Override
		public String toString() {
			
			String bar;
			if (fromBar) bar= "bar";
			else bar= "tab";
			
			String shit="";
			if (hit) shit="*";

			return bar+shit;
		}
		
		@Override
		public boolean equals(Object obj) {
			if (obj instanceof MyInt) {
				MyInt o= (MyInt) obj;
				
				return (fromBar==o.fromBar && hit==o.hit);
			} else {
				return false;
			}
		}

		@Override
		public int compareTo(MyInt o) {
			if (fromBar) {
				
				if (o.fromBar) {
					
					if (hit && o.hit) {
						return 0;
					} else if (hit) {
						return -1;
					} else if (o.hit) {
						return 1;
					} else {
						return 0;
					}
					
				} else {
					
					return -1;
					
				}
				
			} else if (o.fromBar) {
				
				return 1;
				
			} else {
				
				// nessuno dal bar
				
				if (hit && o.hit) return 0;
				else if (hit) return -1;
				else if (o.hit) return 1;
				else return 0;
				
			}
		}
	}
}
